<template>
  <div class="home">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="auto">
        <div class="logo">
          <div class="userhead"></div>
          <span>231231231312</span>
        </div>
        <!-- collapse表示控制导航菜单的展开和折叠 -->
        <!-- router属性表示开启路由模式 -->
        <el-menu
          router
          unique-opened
          :collapse="iscollapse"
          class="el-menu-admin"
          background-color="#F9F9F9"
          @open="handleOpen"
          @close="handleClose"
        >
          <el-menu-item index="Users">
            <i class="el-icon-menu"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>分类管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="CategoryFirst">一级分类管理</el-menu-item>
              <el-menu-item index="CategorySecond">二级分类管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-menu-item index="goods">
            <i class="el-icon-setting"></i>
            <span slot="title">商品管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <!-- 切换按钮 -->
          <div class="toggle-btn" @click="toggle">
            <i class="myicon myicon-menu"></i>
          </div>
          <div class="system-title">乐淘后台管理系统</div>
          <div>
            <el-button type="warning" round class="logout" @click="logout">退出系统</el-button>
          </div>
        </el-header>
        <el-main>
          <!-- 用于子路由的组件 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { logout } from '@/api'
export default {
  name: 'home',
  components: {

  },
  data () {
    return {
      username: '',
      iscollapse: false,
      tableData3: [{
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }],
      multipleSelection: []
    }
  },
  methods: {
    // 用户管理
    gotoUsers () {
      this.router.push({ name: 'Users' })
    },
    toggleSelection (rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    },
    toggle () {
      this.iscollapse = !this.iscollapse
    },
    logout () {
      logout()
        .then(res => {
          console.log(res)
          if (res.data.success) {
            this.$router.push({ name: 'Login' })
            this.$message.success('登出成功！')
          }
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    // min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #545c64;
    height: 100%;
    width: 200px;
    .el-menu {
      border: none;
      background: #535b63;
    }
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
  }
  .logo {
    height: 182px;
    background: #233342;
    background-size: cover;
    position: relative;
    overflow: hidden;
    text-align: center;

    .userhead {
      margin: 50px auto;
      width: 64px;
      height: 64px;
      border: 1px solid #65717b;
      border-radius: 50%;
      background-image: url('../assets/snipaste_20190116_171233.png');
      background-repeat: no-repeat;
      background-size: 100%;
      background-position: center;
    }
    span {
      overflow: hidden;
      text-overflow: ellipsis; //文本溢出显示省略号
      white-space: nowrap; //文本不会换行（单行文本溢出）
      position: absolute;
      width: 64px;
      bottom: 22px;
      transform: translatex(-32px);
      color: #fff;
    }
  }
  .toggle-btn {
    padding: 0 15px;
    margin-left: -20px;
    font-size: 36px;
    color: #fff;
    background: #5ab75d;
    cursor: pointer;
    line-height: 60px;
    &:hover {
      background-color: #4292cf;
    }
  }
  .system-title {
    font-size: 28px;
    color: #2e3f4f;
  }
  .welcome {
    color: white;
  }
  .logout {
    margin-left: 5px;
  }
}
</style>
